﻿using System;
using System.Collections.Specialized;

namespace Melee.Controller.Request
{
    public class Argument<T>
    {
        private string m_Key = null;
        public string Key { get { return m_Key; } }

        public Argument(string key)
        {
            m_Key = key;
        }

        public T ExtractFrom(NameValueCollection queryArguments)
        {
            try
            {
                return (T)Convert.ChangeType(queryArguments[m_Key], typeof(T));
            }
            catch
            {
                return default(T);
            }
        }
    }
}
